<?
  $attributes[0] = explode(',', 'STR,CON,DEX,INT,WIS,CHA');
  $attributes[1] = explode(',', 'HP,MP,AP,ARMOR,XP');
?><div id="statblock">
  <table cellspacing="1" cellpadding="3" class="statbox_table">
  <?
  foreach ($attributes as $attributeRow)
  {
  ?>
    <tr><?
    foreach($attributeRow as $attribute)
    {
      ?><td class="statbox_name" <?= toolTip('tt.'.$attribute) ?>><?= $this->l10n($attribute, 'cq') ?></td><?
    }
    ?></tr><tr><?
    foreach($attributeRow as $attribute)
    {
      ?><td <?= toolTip('tt.'.$attribute) ?> class="statbox_content"><div align="center"><?
      $base = $this->viewCharacter->getCharacterStat($attribute, ',');
      $effective = $this->viewCharacter->getCharacterStat($attribute, ',.effective');
      $current = $this->viewCharacter->getCharacterStat($attribute);
      if ($base == 0 && $effective > 0) $base = $effective;
      
      if ($this->viewCharacter->stats['statincrease'] > 0 && $increasable[$attribute] > 0 && $this->ownCharacter)
      {
        ?><div class="statbox_increase" onclick="ajaxIncreaseStat('<?= $attribute?>')">
          <img src="img/icons/edit_add.png"/></div><?
      } 
      
      ?>
        <span class="statbox_current"><? if ($current != $effective) print('<span id="'.$attribute.'_current">'.$current.'</span> / '); ?></span>
        <span class="statbox_effective"><? print('<span id="'.$attribute.'_effective">'.$effective.'</span>'); ?></span>
        <span class="statbox_base"><? if ($base != $effective) print('(<span id="'.$attribute.'_base">'.$base.'</span>)'); ?></span>
      </div></td><?
    }
    ?></tr><?
  }
  ?>
  </table>
</div>
<?
if ($this->viewCharacter->stats['statincrease'] > 0 && $this->ownCharacter)
{
?>
<div class="banner" id="statincrease_message">
You have <span id="statincreasepoints"><?= $this->viewCharacter->stats['statincrease'] ?></span>
  point<span id="statincrease_plural">s</span> to increase your stats. Click on the 
  <b><img src="img/icons/edit_add.png" align="absmiddle" width="12"/> signs</b> to
  use them all up!
</div>
<?
}
?>
<script>
function ajaxIncreaseStat(statname)
{
  var si = document.getElementById('statincreasepoints');
  var sip = parseInt(si.innerHTML);
  if (sip > 0)
  {
    var elb = document.getElementById(statname+'_base');
    if (elb != null && elb.innerHTML != '') elb.innerHTML = (parseInt(elb.innerHTML)+1);
    var ele = document.getElementById(statname+'_effective');
    if (ele != null && ele.innerHTML != '') ele.innerHTML = (parseInt(ele.innerHTML)+1);
    /*
    var elc = document.getElementById(statname+'_current');
    if (elc != null && elc.innerHTML != '') elc.innerHTML = (parseInt(elc.innerHTML)+1);
    */
    sip--;
    si.innerHTML = sip;
    if (sip != 1) pluralStr = 's'; else pluralStr = '';
    document.getElementById('statincrease_plural').innerHTML = pluralStr;
    sendAjaxRequest('<?= actionUrl('statincrease', 'character', 'stat=') ?>'+statname);
    if (sip == 0)
    {
      document.getElementById('statincrease_message').style.visibility = 'hidden';
      document.getElementById('statblock').innerHTML = '<img src="themes/default/ajax-loader.gif"/>';
      setTimeout("document.location.replace('<?= actionUrl('reload', 'character') ?>');", 1000);
    }    
  }
}
</script>
